package task

import (
	"gddgame.cc/galaxy/common/dsl/game/item"
	"gddgame.cc/galaxy/common/dsl/game/reward"
)

//go:generate msgp

type TaskType byte

//msgp:tuple Task
type Task struct {
	Id         int           `json:"id" msg:"id"`
	Name       string        `json:"name" msg:"name"`
	Desc       string        `json:"desc" msg:"desc"`
	Type       TaskType      `json:"type" msg:"type"`
	Difficult  int           `json:"difficult" msg:"difficult"`
	StartTime  int           `json:"start_time" msg:"start_time"`
	ExpireTime int           `json:"expire_time" msg:"expire_time"`
	Reward     reward.Reward `json:"reward" msg:"reward"`
	IsAddUp    bool          `json:"is_add_up" msg:"is_add_up"`
	Goal       int           `json:"goal" msg:"goal"`

	Extend interface{} `json:"extend" msg:"extend"`
}

func NewTask(task *GameTask, language string, items map[int]*item.Item) *Task {
	ext := &Task{
		Id:         task.Id,
		Name:       task.Name[language],
		Desc:       task.Desc[language],
		Type:       task.Type,
		Difficult:  task.Difficult,
		StartTime:  0,
		ExpireTime: 0,
		Reward:     task.Reward.Copy(),
		IsAddUp:    task.IsAddUp,
		Goal:       int(task.GetGoal()),
		Extend:     task.Extend,
	}
	if task.StartTime != nil {
		ext.StartTime = int(task.StartTime.Unix())
	}
	if task.ExpireTime != nil {
		ext.ExpireTime = int(task.ExpireTime.Unix())
	}

	// 设定Item名称
	ext.Reward.BindInfo(items, language)
	return ext
}
